package com.study.springaidemo1.controller;
import org.springframework.ai.chat.client.ChatClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class OllamaChatController {

    @Autowired
    @Qualifier("ollamaChatClient")
    private ChatClient ollamaClient;

    @Autowired
    @Qualifier("ollamaChatClientV2")
    private ChatClient ollamaClientV2;

    @Autowired
    @Qualifier("openAIClientDeepSeek")
    private ChatClient openAIClientDeepSeek;
    @GetMapping("/chat")
    public String chat(String prompt){
        return ollamaClient.prompt()
                .user(prompt)
                .call()// call 阻塞方式的调用
                .content();
    }
    @GetMapping("/stream")
    public Flux<String> stream(String prompt){
        return ollamaClient.prompt()
                .user(prompt)
                .stream()
                .content();
    }
    @GetMapping("/chatV2")
    public String chatV2(String prompt){
        return ollamaClientV2.prompt()
                .user(prompt)
                .call()
                .content();
    }

    @GetMapping("/streamV2")
    public Flux<String> streamV2(String prompt){
        return ollamaClientV2.prompt()
                .user(prompt)
                .stream()
                .content();
    }

    @GetMapping("/chatDeepSeek")
    public String chatDeepSeek(String prompt){
        return openAIClientDeepSeek.prompt()
                .user(prompt)
                .call()
                .content();
    }
    @GetMapping("/streamDeepSeek")
    public Flux<String> streamDeepSeek(String prompt){
        return openAIClientDeepSeek.prompt()
                .user(prompt)
                .stream()
                .content();
    }
}
